package com.qf.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cache.annotation.CacheDel;
import com.cache.annotation.CacheUsing;
import com.qf.commons.PinyinUtil;
import com.qf.dao.CityDao;
import com.qf.entity.City;
import com.qf.service.CityService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

/**
 * (City)表服务实现类
 *
 * @author makejava
 * @since 2020-09-11 09:11:59
 */
@Service("cityService")
public class CityServiceImpl extends ServiceImpl<CityDao, City> implements CityService {

    @Override
    @CacheUsing(key = "'cityList'")
    public List<City> list() {
        System.out.println("查询了城市列表！！！！");
        return super.list();
    }

    /**
     * 根据id查询城市信息
     * @param id
     * @return
     */
    @Override
    @CacheUsing(key = "'mycity' + #id")
    public City getById(Serializable id) {
        System.out.println("查询数据库：" + id);
        return super.getById(id);
    }

    @Override
    @Transactional
    @CacheDel(key = "'cityList'")
    public boolean save(City entity) {

        //通过城市名称生成pigyin
        String pinyin = PinyinUtil.toPinyin(entity.getCityName());
        entity.setCityPinyin(pinyin);

        //保存城市信息
        return super.save(entity);
    }
}